<template>
	<view class="container">
		<mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption"
			@up="upCallback">
			<view class="log-list">
				<view v-for="(item, index) in list.data" :key="index" class="log-item">
					<view class="item-left flex-box">
						<view class="rec-status">
							<text>{{ '充值成功' }}</text>
						</view>
						<view class="rec-time">
							<text>{{ item.pay_time }}</text>
						</view>
					</view>
					<view class="item-right">
						<text>+{{ item.actual_money }}元</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
	import * as OrderApi from '@/api/recharge/order'
	import {
		getEmptyPaginateObj,
		getMoreListData
	} from '@/core/app'

	const pageSize = 10

	export default {
		components: {
			MescrollBody
		},
		// 局部混入
		mixins: [MescrollMixin],

		data() {
			return {
				// 充值记录列表
				list: getEmptyPaginateObj(),
				// 上拉加载配置
				upOption: {
					// 首次自动执行
					auto: true,
					// 每页数据的数量：默认10
					page: {
						size: pageSize
					},
					// 数量大于12条时才显示无更多数据
					noMoreSize: 12,
					// 空布局
					empty: {
						tip: '亲，暂无充值记录~'
					}
				},
			}
		},
		methods: {
			/**
			 * 上拉加载的回调 (页面初始化时也会执行一次)
			 * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
			 * @param {Object} page
			 */
			upCallback(page) {
				const that = this
				// 设置列表数据
				this.getLogList(page.num)
					.then(list => {
						const curPageLen = list.data.length
						const totalSize = list.data.total
						that.mescroll.endBySize(curPageLen, totalSize)
					})
					.catch(() => that.mescroll.endErr())
			},
			
			// 获余额账单明细列表
			getLogList(pageNo = 1) {
				const that = this
				return new Promise((resolve, reject) => {
					OrderApi.list({ page: pageNo })
						.then(res => {
							// 合并新数据
							const newList = res.data.list
							that.list.data = getMoreListData(newList, that.list, pageNo)
							resolve(newList)
						})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page,
	.container {
		background: #fff;
	}

	.log-list {
		padding: 0 30rpx;
	}

	.log-item {
		font-size: 28rpx;
		padding: 20rpx 20rpx;
		line-height: 1.8;
		border-bottom: 1rpx solid rgb(238, 238, 238);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.rec-status {
		color: #333;

		.rec-time {
			color: rgb(160, 160, 160);
			font-size: 26rpx;
		}
	}
</style>
